require 'rubygems'
gem 'quality_rake_tasks'
require 'quality_rake_tasks'

#---------------------------------------------------------------------------------------------------------------------------------
# Specification and description

module Project
  PrettyName    = "Rake Command Completion"
  Name          = "rake-command-completion"
  RubyForgeName = "rake-completion"
  Version       = "0.0.1" 
end

specification = Gem::Specification.new do |s|
  s.name    = Project::Name
  s.summary = "Adds bash command-line completion for the rake command."
  s.version = Project::Version
  s.author  = 'Nicholas Seckar, Saimon Moore, Err the Blog, Lee Marlow, Tyler Rick'
  s.description = s.summary
  #s.email = "#{Project::Name}-developer@rubyforge.org"
  s.email = "rubyforge.org@tylerrick.com"
  s.homepage = "http://#{Project::RubyForgeName}.rubyforge.org/"
  s.rubyforge_project = Project::Name
  s.platform = Gem::Platform::RUBY

  # Documentation
  s.has_rdoc = true
  s.extra_rdoc_files = ['Readme']
  s.rdoc_options << '--title' << Project::Name << '--main' << 'Readme' << '--line-numbers'

  # Files
  s.files = FileList['{lib,test,examples}/**/*.rb', 'bin/*', 'Readme'].exclude('ToDo').to_a
  s.test_files = Dir.glob('test/*.rb')
  #s.require_path = "lib"
  s.executables = "command_completion_for_rake"
end


#---------------------------------------------------------------------------------------------------------------------------------
# Tests

require 'rake/testtask'

task :default => :test
SharedTasks.normal_test_task

#---------------------------------------------------------------------------------------------------------------------------------
# Documentation

require 'rake/rdoctask'

SharedTasks.rdoc_task do |rdoc|
  rdoc.title = Project::PrettyName
  rdoc.rdoc_files.include(
    "bin/*"
  )
end


#---------------------------------------------------------------------------------------------------------------------------------
# Deployment

# See config/deploy.rb

#---------------------------------------------------------------------------------------------------------------------------------
# Packaging

require 'rake/gempackagetask'
Rake::GemPackageTask.new(specification) do |package|
	 package.need_zip = true
	 package.need_tar = true
end
# To generate a gem, simply execute:
#   rake package
# or
#   rake pkg/#{spec.name}-#{spec.version}.gem

#---------------------------------------------------------------------------------------------------------------------------------
# Publishing

require 'rake/contrib/sshpublisher'

desc "Upload RDoc to RubyForge"
task :publish_rdoc => [:rdoc] do
  Rake::SshDirPublisher.new("#{ENV['RUBYFORGE_USER']}@rubyforge.org", "/var/www/gforge-projects/#{Project::RubyForgeName}", "doc").upload
end

# This can be invoked from the command line:
#   rake release RUBYFORGE_USER=myuser \
#                RUBYFORGE_PASSWORD=mypassword
task :verify_user do
  raise "RUBYFORGE_USER environment variable not set!" unless ENV['RUBYFORGE_USER']
end
task :verify_password do
  raise "RUBYFORGE_PASSWORD environment variable not set!" unless ENV['RUBYFORGE_PASSWORD']
end

desc "Publish package files on RubyForge."
task :publish_packages => [:verify_user, :verify_password, :package] do
  require 'meta_project'
  require 'rake/contrib/xforge'
  release_files = FileList[
    "pkg/#{Project::Name}-#{Project::Version}.gem",
    "pkg/#{Project::Name}-#{Project::Version}.tgz",
    "pkg/#{Project::Name}-#{Project::Version}.zip"
  ]

  Rake::XForge::Release.new(MetaProject::Project::XForge::RubyForge.new(Project::RubyForgeName)) do |release|
    release.user_name = ENV['RUBYFORGE_USER']
    release.password = ENV['RUBYFORGE_PASSWORD']
    release.files = release_files.to_a
    release.package_name = "#{Project::Name}"
    release.release_name = "#{Project::Name} #{Project::Version}"
    release.release_changes = ''
    release.release_notes = ''
  end
end

#---------------------------------------------------------------------------------------------------------------------------------
